package d7_homework.d3_homeworkday06.d4_fourthquestion;

import java.util.*;

public class Test01 {
    public static void main(String[] args) {
        //目标: 完成"我的订单"业务需求
        //创建存放订单的集合
        List<List<ProductItem>> list = new ArrayList<>();
        //1、创建一个集合进行存储每一个商品
        //用ArrayList<> 特点: 有序, 可重复, 有索引
        List<ProductItem> productItems = new ArrayList<>();//一行经典代码,以后基本都要写成多态

        //2、创建学生对象,封装商品对象
        /*Collections.addAll(productItems, new ProductItem(1,  "100823178123",001,"ikbc c87 机械键盘 有线键盘 游戏键盘", 317.97),
                new ProductItem(1, "100149628134", ));*/
        //创建所及数对象
        Random rd = new Random();

        //创建订单线对象
        ProductItem productItem1 = new ProductItem(1, rd.nextInt(100000000), 1, "酸奶", 50);
        ProductItem productItem2 = new ProductItem(2, rd.nextInt(100000000), 2, "手机", 5000);
        ProductItem productItem3 = new ProductItem(3, rd.nextInt(100000000), 3, "手机壳", 45);
        ProductItem productItem4 = new ProductItem(4, rd.nextInt(100000000), 4, "漱口水", 35);
        Collections.addAll(productItems, productItem1,productItem2,productItem3,productItem4);
       //一个订单可能有多个商品,不是每一个商品一个订单
        //将每一个订单存放到每一个集合中
        list.add(productItems);

        //遍历集合,获取订单信息,并展示在console
        //利用迭代器
        Iterator<List<ProductItem>> it = list.iterator();
        while(it.hasNext()){
            List<ProductItem> items = it.next();
            Iterator<ProductItem> it2 = items.iterator();
            while(it2.hasNext()){
                ProductItem productInfo = it2.next();
                System.out.println(productInfo.getProductItemId() + ","
                        +productInfo.getProductItemIdNumber() + ","
                        +productInfo.getProductNumber() + ","
                        +productInfo.getProductName()+ ","
                        + productInfo.getPrice());
            }
        }

    }
}
